package com.ymatou.app.api.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.app.api.parameter.AddAddressBean;
import com.ymatou.app.api.service.AddAddressCall;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.business.service.YmtCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 新增收货地址 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddAddress {
	private static AddAddressBean addaddressbean;
	private static AddAddressCall addaddresscall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增收货地址");
	}

	@Before
	public void caseUp() {
		addaddressbean = new AddAddressBean();
		addaddresscall = new AddAddressCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addaddresscall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddAddress_001() {
		Logger.start(true,"新增收货地址成功");
		try {
			// String UserName = "13511867828";
			String PassWord = "123456";
			// 注册获取token和userid

			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			// 清理数据
			/*
			 * YmtCallService ymt = new YmtCallService(UserName,PassWord);
			 * if(ymt.getAddressId().size()>4){ ymt.delAddressById((Integer)
			 * ymt.getAddressId().get(0)); }
			 */
			addaddressbean.setUserId(UserId);
			Logger.comment("UserName:" + UserName);
			Logger.comment("UserId:" + UserId);
			String Address1 = "上海市上海市闸北区灵石路695号3号楼1404室";
			addaddressbean.setAddress1(Address1);
			Logger.comment("Address1:" + Address1);
			String ProvinceName = "上海市";
			addaddressbean.setProvinceName(ProvinceName);
			Logger.comment("ProvinceName:" + ProvinceName);
			String CityName = "上海市";
			addaddressbean.setCityName(CityName);
			Logger.comment("CityName:" + CityName);
			String DistrictName = "闸北区";
			addaddressbean.setDistrictName(DistrictName);
			Logger.comment("DistrictName:" + DistrictName);
			String Details = "灵石路695号3号楼1404室";
			addaddressbean.setDetails(Details);
			Logger.comment("Details:" + Details);
			String PostCode = "200001";
			addaddressbean.setPostCode(PostCode);
			Logger.comment("PostCode:" + PostCode);
			String MobileNum = TestDataManager.getPhoneNum();
			addaddressbean.setMobile(MobileNum);
			Logger.comment("MobileNum:" + MobileNum);
			String Recipient = TestDataManager.getChineseName();
			addaddressbean.setRecipient(Recipient);
			Logger.comment("Recipient:" + Recipient);
			String Email = TestDataManager.getEmail();
			addaddressbean.setEmail(Email);
			Logger.comment("Recipient:" + Recipient);
			boolean IsDefault = false;
			addaddressbean.setIsDefault(IsDefault);
			addaddressbean.setAccessToken(AccessToken);
			// 设置数据，发送
			addaddresscall.setData(addaddressbean);
			addaddresscall.callService();
			Logger.comment("addaddresscall send:" + addaddresscall.getEntityString());
			Logger.comment("addaddresscall response:" + addaddresscall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, addaddresscall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE0, addaddresscall.getBCode(), "验证BCode");
			Logger.verifyEquals(ECode.APP_MSG1, addaddresscall.getMsg(), "验证消息");
			Logger.verifyEquals(true, addaddresscall.getResult(), "验证result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AddAddress_002() {
		Logger.start(true,"收货地址增加超过5个");
		try {
			// String UserName = "13511867828";
			String PassWord = "123456";
			// 注册获取token和userid

			com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean urb = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall uc = JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			Integer UserId = uc.getUserid();
			String AccessToken=uc.getAccessToken();
			
			String UserName = urb.getLoginMobile();
			String ip=urb.getClientIp();
			// 数据不足5条。添加够5条
			YmtCallService ymt = new YmtCallService();
			for (int i = 0; i < 5; i++) {
				ymt.addAddress(AccessToken, UserId);
			}
			addaddressbean.setUserId(UserId);
			Logger.comment("UserId:" + UserId);
			String Address1 = "上海市上海市闸北区灵石路695号3号楼1404室";
			addaddressbean.setAddress1(Address1);
			Logger.comment("Address1:" + Address1);
			String ProvinceName = "上海市";
			addaddressbean.setProvinceName(ProvinceName);
			Logger.comment("ProvinceName:" + ProvinceName);
			String CityName = "上海市";
			addaddressbean.setCityName(CityName);
			Logger.comment("CityName:" + CityName);
			String DistrictName = "闸北区";
			addaddressbean.setDistrictName(DistrictName);
			Logger.comment("DistrictName:" + DistrictName);
			String Details = "灵石路695号3号楼1404室";
			addaddressbean.setDetails(Details);
			Logger.comment("Details:" + Details);
			String PostCode = "200001";
			addaddressbean.setPostCode(PostCode);
			Logger.comment("PostCode:" + PostCode);
			String MobileNum = TestDataManager.getPhoneNum();
			addaddressbean.setMobile(MobileNum);
			Logger.comment("MobileNum:" + MobileNum);
			String Recipient = TestDataManager.getChineseName();
			addaddressbean.setRecipient(Recipient);
			Logger.comment("Recipient:" + Recipient);
			String Email = TestDataManager.getEmail();
			addaddressbean.setEmail(Email);
			Logger.comment("Recipient:" + Recipient);
			boolean IsDefault = false;
			addaddressbean.setIsDefault(IsDefault);
			addaddressbean.setAccessToken(AccessToken);
			// 设置数据，发送
			addaddresscall.setData(addaddressbean);
			addaddresscall.callService();
			/*
			 * Logger.debug(addaddresscall.getEntityString());
			 * Logger.debug(addaddresscall.getReturnData());
			 */
			Logger.comment("addaddresscall send:" + addaddresscall.getEntityString());
			Logger.comment("addaddresscall response:" + addaddresscall.getReturnData());
			Logger.verifyEquals(ECode.FAILED400, addaddresscall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE0, addaddresscall.getBCode(), "验证BCode");
			Logger.verifyEquals(ECode.APP_MSG2, addaddresscall.getMsg(), "验证消息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}